package com.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;



/**
 * Created by Kuson on 17/5/28.
 */

public class PreferenceUtils {


    public static String http_url = "http_url";
    public static String device_address = "device_address";
    /**
     * 保存数据
     */
    public static void setData(Context context,String key, String value) {
        getPreference(context).edit().putString(key, value).apply();
    }

    public static SharedPreferences getPreference(Context context) {
        return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
    }

    /**
     * 获取数据
     *
     * @param key
     * @return
     */
    public static String getData(Context context,String key) {
        return getPreference(context).getString(key, "");
    }
    public static String HexToASCII(String hexString) {

        //String hexString = "5341434330303335302D533242465044"; // 十六进制字符串
        int length = hexString.length();
        StringBuilder asciiString = new StringBuilder();

        for (int i = 0; i < length; i += 2) {
            String hexPair = hexString.substring(i, i + 2); // 每两个字符组合成一对
            int decimal = Integer.parseInt(hexPair, 16); // 转换为十进制
            asciiString.append((char) decimal); // 转换为字符并附加到结果中
        }

        LogUtils.e("ASCII String: " + asciiString.toString()); // 输出结果
        return asciiString.toString();
    }


}
